﻿using System;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class ProtectRecord : WorksheetLevelRecord
    {
        private bool _protected;

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            this._protected =
            context.ReadUInt16() != 0;
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.Protect; }
        }

        internal override void Apply(BiffReaderWorksheetContext context)
        {
            context.Worksheet.EnsureProtection().Sheet = true;
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            if (_protected)
                context.Write((ushort)1);
            else
            {
                context.Write((ushort)0);
            }
        }
    }
}